package com.maixun.lib_business_college.qa.new_qa

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.maixun.lib_business_college.R
import com.maixun.lib_business_college.entity.QABeen
import com.maixun.lib_business_college.qa.QAAdapter
import com.maixun.lib_comment.ui.BaseMVPFragment
import com.maixun.lib_network.entity.NetBaseListBeen
import kotlinx.android.synthetic.main.college_fragment_qa_new.*

/**
 * @author：Lmoumou
 * @date：2020/11/4
 */
class NewQAFragment : BaseMVPFragment<NewQAPresenterImpl>(), NewQAContract.View {

    companion object {
        fun newInstance(): Fragment = NewQAFragment()
    }

    override val mPresenter: NewQAPresenterImpl by lazy { NewQAPresenterImpl(this) }

    override fun getLayoutId(): Int = R.layout.college_fragment_qa_new

    override fun isLazyLoad(): Boolean {
        return true
    }

    private val descCode = 0
    private var typeId: String? = null
    private var current = 1

    override fun loadData() {
        mPresenter.pQADataList(descCode, typeId, null, current)
    }

    private val dataList by lazy { mutableListOf<QABeen>() }
    private val adapter by lazy { QAAdapter(mContext, dataList) }
    override fun initView(rootView: View, savedInstanceState: Bundle?) {
        mRecyclerView.adapter = adapter
    }


    override fun vQADataList(result: NetBaseListBeen<QABeen>?) {
        result?.run {
            if (this.current == 1) {
                dataList.clear()
            }
            this@NewQAFragment.current = current + 1
            dataList.addAll(this.records)
            adapter.notifyDataSetChanged()
        }
    }
}